//
//  UIBarButtonItem+Extension.swift
//  SinaWeiBo
//
//  Created by Vergil on 2017/4/6.
//  Copyright © 2017年 Vergil. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    /// 便利构造 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize
    ///   - nornalColor: nornalColor
    ///   - highLightColor: highLightColor
    ///   - target: target
    ///   - action: action
    ///   - isBack: 是否是返回按钮
    convenience init(title: String,fontSize: CGFloat = 16,normalColor: UIColor = UIColor.darkGray,highLightColor: UIColor = UIColor.orange,target: Any?,action: Selector,isBack: Bool = false) {
        
        let btn = UIButton()
        btn.setTitle(title, for: .normal)
        btn.setTitleColor(normalColor, for: .normal)
        btn.setTitleColor(highLightColor, for: .highlighted)
        btn.addTarget(target, action: action, for: .touchUpInside)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: fontSize)
        
        if isBack {
            btn.setImage(UIImage(named: "navigationbar_back_withtext"), for: .normal)
            btn.setImage(UIImage(named: "navigationbar_back_withtext_highlighted"), for: .highlighted)
        }
        btn.sizeToFit()
        
        self.init(customView:btn)
        
    }
    
}
